package org.skycastle.megastructure

import com.jme.bounding.BoundingBox
import com.jme.image.Texture
import com.jme.scene.shape.Sphere
import com.jme.math.Vector3f
import com.jme.system.DisplaySystem
import com.jme.util.TextureManager
import utils.ResourceLoader

/**
 *
 *
 * @author Hans Haggstrom
 */

class Ball(radius: Float,
           textureName: String,
           position: Vector3f,
           resolution: Int ) extends Appearance {

  def this( radius: Float,
            textureName: String  ) {
    this ( radius, textureName, new Vector3f(), 16 )
  }

  protected def createSpatial(display : DisplaySystem) = {

    val s = new Sphere("Sphere", resolution, resolution, radius)
    val texture = TextureManager.loadTexture(ResourceLoader.getResourceURL(textureName),
      Texture.MinificationFilter.BilinearNearestMipMap,
      Texture.MagnificationFilter.Bilinear)

    s.setLocalTranslation( position )
    s.setModelBound(new BoundingBox())
    s.updateModelBound()

    val ts = display.getRenderer().createTextureState()
    ts.setEnabled(true);
    ts.setTexture(texture);
    s.setRenderState(ts);

    s
  }




}